
function circle ({number = 10, radius=0.5}={}) {
  const vecs = [];
  
  for (let i = 0; i < number; i++) {
    vecs.push(new Vec({
      x: Math.sin(Math.PI * 2 * (i / number)) * radius,
      y: Math.cos(Math.PI * 2 * (i / number)) * radius,
    }))
  }
  
  return vecs.toClosure();
}

function rect({height=0.5, width=0.5}={}) {
  return [
    new Vec({x: -width, y: -height}),
    new Vec({x: -width, y:  height}),
    new Vec({x:  width, y:  height}),
    new Vec({x:  width, y: -height}),
  ].toClosure();
}

function zigzag({zigs = 5, teethWidth=0.08, eccn=0.15, width=0.5, ends=0.6, toClosure=false}={}) {

  const starts = -( zigs * teethWidth / 2);

  eccn = Math.max(Math.min(eccn, 0.45), 0);

  const vecs = [new Vec({x: -ends, y:starts})];

  for (let i = 0; i < zigs; i++) {

    if(eccn < 1e-4) {
      vecs.push(
        new Vec({x:-width, y: i        * teethWidth + starts}),
        new Vec({x: width, y:(i + 0.5) * teethWidth + starts}),
      )
    } else {
      vecs.push(
        new Vec({x:-width, y: i               * teethWidth + starts}),
        new Vec({x: width, y:(i + 0.5 + eccn) * teethWidth + starts}),
        new Vec({x: width, y:(i + 0.5 - eccn) * teethWidth + starts}),
      )
    }

  }

  vecs.push(new Vec({x: -ends, y: (zigs) * teethWidth + starts}));

  if (toClosure) {
    vecs.toClosure();
  }
  return vecs;
}


function bezierRect({height=0.5, width=0.5, step=3}={}) {
  const points = [
    new Vec({x:      0, y: -height}),
    new Vec({x: -width, y: -height}),
    new Vec({x: -width, y:       0}),
    new Vec({x: -width, y:  height}),
    new Vec({x:      0, y:  height}),
    new Vec({x:  width, y:  height}),
    new Vec({x:  width, y:       0}),
    new Vec({x:  width, y: -height}),
  ].toClosure();

  const len = step * 3;
  const newPoints = [];
  for (let i = 0; i < points.length-1; i+=2) {
    const p = [points[i], points[i+1], points[i+1], points[i+2]];
    for (let s = 1; s < len; s++) {
      const t = s/len;
      newPoints.push(new Vec({
        x: (1-t)**3 * p[0].x + 3 * (1-t)**2 * t * p[1].x + 3 * (1-t) * t**2 * p[2].x + t**3 * p[3].x,
        y: (1-t)**3 * p[0].y + 3 * (1-t)**2 * t * p[1].y + 3 * (1-t) * t**2 * p[2].y + t**3 * p[3].y,
      }))
    }
  }

  return newPoints.toClosure();
}

function line({len=1.9, angle=0, cent={}}={}) {
  return [
    new Vec({x:  len/2}).spin(angle).plus(cent),
    new Vec({x: -len/2}).spin(angle).plus(cent)
  ]
}